<?php

class company_cls extends pl_db_opt_cls
{
	
	public function __construct()
	{
		global $_db_name;
		$this->setDbName($_db_name);
		$this->setTblName('company');
	}
	
	
	public function add_company($data)
	{
		return $this->insert($data, 'IGNORE');
	}
	
	
	public function del_company($company_id)
	{
		$company_id = intval($company_id);
		if($company_id < 1) return false;
		$where_str = "company_id='{$company_id}'";
		
		return $this -> delete($where_str);
	}
	
	
	public function update_company($data, $company_id)
	{
		if( !is_array($data) || empty($data) )
		{
			return false;
		}
		
		$company_id = intval($company_id);
		$where_str = "company_id = '{$company_id}'";
		
		return $this->update($data, $where_str);
	}
	
	public function get_company_info($company_id, $select_str = '*')
	{
		$company_id = intval($company_id);
		$where_str = "company_id = '{$company_id}'";
		return $this->getRow($where_str, $select_str);
	}

	public function get_company_list($b_select_count = false, $where_str = '', $order_by = '', $limit = '')
	{  	
	    
		$sql = "SELECT * FROM {$this->db_name}.{$this->tbl_name}";		
		$sql_where = '';
		$sql_where_sp = '';
		
		if( strlen($where_str) > 0 )
		{
			$sql_where_sp = strlen($sql_where)>0?' AND ':'';
			$sql_where = $sql_where . $sql_where_sp . $where_str;
		}
		
		if ( strlen($sql_where) > 0 )
		{
			$sql .= " WHERE " . $sql_where;
		}
		
		if ( $b_select_count == true )
		{
			//统计记录数
			$tmp = $this->getList($b_select_count, $sql);
			return $tmp;
		}		
	
		return $this->getList($b_select_count, $sql, $order_by, $limit);
	}
}